package cn.com.idmy.auth.oauth.token;

import cn.com.idmy.auth.context.Request;
import cn.com.idmy.auth.oauth.JwtTokenUtil;
import cn.com.idmy.auth.oauth.OauthJwtManager;
import cn.com.idmy.auth.oauth.model.AccessTokenOut;
import cn.com.idmy.auth.oauth.model.RefreshTokenIn;
import lombok.Data;

@Data
public class OauthTokenRefreshTokenImpl implements OauthToken {
    protected OauthJwtManager oauthJwtManager;

    @Override
    public AccessTokenOut getToken(Request request) {
        RefreshTokenIn in = request.getParams().toJavaObject(RefreshTokenIn.class);
        in.setUri(request.getUri());
        Object id = JwtTokenUtil.parseId(in.getRefreshToken(), oauthJwtManager.getOauthConfig().getRefreshAlgorithm());
        return oauthJwtManager.createAccessToken(id, in);
    }
}
